/*
 * QuenchThirst.java
 *
 * Created on March 27, 2007, 11:24 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.State;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class QuenchThirst extends State<Miner> {
    public static final State<Miner> INSTANCE = new QuenchThirst();
    /** Creates a new instance of QuenchThirst */
    private QuenchThirst() {
    }

    public void enter(Miner m) {
        if (m.getLocation() != Locations.SALOON){
            m.setLocation(Locations.SALOON);
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": Boy, ah sure is thusty! Walking to the saloon");
        }
    }

    public void execute(Miner m) {
        if (m.isThirsty()){
            m.buyAndDrinkWhiskey();
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": That's mighty fine sippin liquer");
            m.getStateMachine().changeState(EnterMineAndDigForNugget.INSTANCE);
        } else {
            System.err.println("ERROR! ERROR! ERROR!");
        }
    }

    public void exit(Miner m) {
        System.out.println(EntityNames.getNameOfEntity(m.getId())+": Leaving the saloon, feelin' good");
    }

    public boolean onMessage(Miner m, Telegram t) {
        return false;
    }

    
}
